<template>
	<view class="record-container">
		<!-- 记录列表 -->
		<view class="record-list">
			<view class="record-item" v-for="(item, index) in habitList" :key="index">
				<view class="record-header">
					<text class="habit-name">{{ item.shHcontent }}</text>
				</view>
				<view class="record-info">
					<view class="info-item">
						<text class="label">习惯频率：</text>
						<text class="value">{{ item.shFrequency }}</text>
					</view>
					<view class="info-item">
						<text class="label">开始时间：</text>
						<text class="value">{{ item.shCreatetime }}</text>
					</view>
					<view class="info-item">
						<text class="label">持续时间：</text>
						<text class="value">{{ item.shDuration }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 暂无数据 -->
		<view class="empty" v-if="habitList.length === 0">
			<image src="/static/empty.png" mode="aspectFit"></image>
			<text>暂无习惯记录</text>
		</view>
	</view>
</template>

<script>
import { getbystuid } from '@/api/habit'
import { reactive, toRefs } from 'vue';
export default {
	setup() {
		const state = reactive({
			habitList: [
				{
					shHcontent: '每天阅读专业书籍1小时',
					shFrequency: '每天',
					shCreatetime: '2024-03-01',
					shDuration: '1个月',
				}
			]
		})
		function getHabit(){
			getbystuid(uni.getStorageSync("student").sSid).then(res=>{
				if(res.code == 1){
					state.habitList = res.data;
				}
			})
		}
		getHabit();
		return{
			...toRefs(state)
		}
	}
}
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}

.record-container {
	padding: 30rpx;

	.record-list {
		.record-item {
			background-color: #fff;
			border-radius: 12rpx;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.record-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;

				.habit-name {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
				}

				.status {
					font-size: 24rpx;
					padding: 4rpx 12rpx;
					border-radius: 6rpx;

					&.ongoing {
						color: #119790;
						background-color: rgba(17, 151, 144, 0.1);
					}

					&.completed {
						color: #52c41a;
						background-color: rgba(82, 196, 26, 0.1);
					}
				}
			}

			.record-info {
				.info-item {
					display: flex;
					margin-bottom: 10rpx;

					&:last-child {
						margin-bottom: 0;
					}

					.label {
						font-size: 28rpx;
						color: #666;
						width: 160rpx;
					}

					.value {
						font-size: 28rpx;
						color: #333;
						flex: 1;
					}
				}
			}
		}
	}

	.empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 200rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			margin-bottom: 20rpx;
		}

		text {
			font-size: 28rpx;
			color: #999;
		}
	}
}
</style>